<span class="layui-breadcrumb"  lay-separator="/">
  <a href="/">商家后台</a>
  <a><cite>选择分类</cite></a>
</span>
<div class="mt_2">
		<!-- <div class="layui-form-item">
			<label class="layui-form-label">选择框</label>
			<div class="layui-input-block">
				<select name="city" lay-verify="required">
					<option value=""></option>
					<option value="0">衣服</option>
					<option value="1">裤子</option>
					<option value="2">鞋子</option>
				</select><div class="layui-unselect layui-form-select"><div class="layui-select-title"><input type="text" placeholder="请选择" value="" readonly="" class="layui-input layui-unselect"><i class="layui-edge"></i></div><dl class="layui-anim layui-anim-upbit" style=""><dd lay-value="" class="layui-select-tips">请选择</dd><dd lay-value="0" class="">衣服</dd><dd lay-value="1" class="">裤子</dd><dd lay-value="2" class="">鞋子</dd></dl></div>
			</div>
		</div> -->
		<div class="selector clearfix">
			<div class="fl cheak1 p_1 pr">
                <?php foreach($cat1 as $v):?>
				<p class="blue clearfix" onclick="choice_cat(this,1)" tid='<?=$v['id']?>'><span class="fl"><?=$v['cat_title']?></span><span class="fr none">&gt;&gt;</span></p>
                <?php endforeach;?>
			</div>
			<div class="fl p_1 cheak2 pr">
			</div>
			<div class="fl p_1 cheak3 pr">
			</div>
		</div>
		<div class="layui-form-item mt_2">
                <button style="display:block;width:30%;" class="layui-btn m_auto" onclick="next()">下一步</button>
		</div>
</div>
<script>
//选择分类的函数
function choice_cat(e,type){
    $(e).siblings().removeClass('active');
    $(e).addClass('active');
    var pid = $(e).attr('tid');
    if(type==1){
        var index = layer.load(2, {time: 10*1000});
        $.ajax({
            url:'<?=url("goodscat/getsub")?>',
            method:'post',
            dataType:'json',
            data:{pid:pid},
            success:function(rs){
                var html = '';
                $.each(rs.data,function(i,e){
                    html += '<p class="blue clearfix" onclick="choice_cat(this,2)" tid="'+i+'"><span class="fl">'+e+'</span><span class="fr none">&gt;&gt;</span></p>';
                });
                $('.cheak2').html(html);
                $('.cheak3').html('');
            },
            complete:function(){
                layer.closeAll('loading');
            }
        });
    }else if(type==2){
        var index = layer.load(2, {time: 10*1000});
        $.ajax({
            url:'<?=url("goodscat/getsub")?>',
            method:'post',
            dataType:'json',
            data:{pid:pid},
            success:function(rs){
                var html = '';
                $.each(rs.data,function(i,e){
                    html += '<p class="blue clearfix" onclick="choice_cat(this,3)" tid="'+i+'"><span class="fl">'+e+'</span><span class="fr none">&gt;&gt;</span></p>';
                });
                $('.cheak3').html(html);
            },
            complete:function(){
                layer.closeAll('loading');
            }
        });
    }
}
//下一步函数
function next(){
    var id = $(".active:last").attr('tid');
    if(typeof(id) == 'undefined'){
        alert_msg('请选择分类');
    }else{
        var url = "<?=url('goods/add')?>?cat_id="+id;
        <?php if($id):?>
            url = "<?=url('goods/edit')?>?cat_id="+id+"&id="+<?=$id?>;
        <?php endif;?>
        console.log(url);
        window.location.href=url;
    }
}
</script>
